package listados;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import com.toedter.calendar.JDateChooser;

import accesoADatos.AccesoADatos;
import datos.Reserva;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ListadosTurnos extends ListadoDialog {
	private SimpleDateFormat formateador = new SimpleDateFormat("dd'/'MM'/'yyyy");
	private static final long serialVersionUID = 1L;
	private JDateChooser cFechaFin;
	private JLabel lProfesional;
	private JLabel lServicio;
	private JComboBox cbCliente;
	private JComboBox cbProfesional;
	private JLabel lFechaFin;
	private JLabel lFechaInicio;
	private JDateChooser cFechaInicio;

	
	
	@SuppressWarnings("unchecked")
	public ListadosTurnos(JFrame frame,Vector v) {
		super(frame,v);
		this.setTitle("Listado de Turnos");
		{
			lProfesional = new JLabel();
			super.jPanel1.add(lProfesional);
			lProfesional.setText("Profesional");
			lProfesional.setHorizontalAlignment(SwingConstants.CENTER);
			lProfesional.setPreferredSize(new java.awt.Dimension(100,21));
			lProfesional.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			lProfesional.setSize(100, 21);
			lProfesional.setForeground(new Color(0,0,0));
		}
		{
			List lp = AccesoADatos.getInstance().getProfesionales();
			lp.add(0, new String("Todos"));
			ComboBoxModel cbProfesionalModel = 
				new DefaultComboBoxModel(
						lp.toArray());
			cbProfesional = new JComboBox();
			super.jPanel1.add(cbProfesional);
			cbProfesional.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			cbProfesional.setModel(cbProfesionalModel);
			cbProfesional.setPreferredSize(new java.awt.Dimension(128, 21));
		}
		{
			lFechaInicio = new JLabel();
			super.jPanel1.add(lFechaInicio);
			lFechaInicio.setText("Fecha inicio");
			lFechaInicio.setHorizontalAlignment(SwingConstants.CENTER);
			lFechaInicio.setPreferredSize(new java.awt.Dimension(100,21));
			lFechaInicio.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			lFechaInicio.setSize(100, 21);
			lFechaInicio.setForeground(new Color(0,0,0));
		}
		{
			cFechaInicio = new JDateChooser();
			cFechaInicio.setDate(new Date());
			cFechaInicio.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			super.jPanel1.add(cFechaInicio);
			cFechaInicio.setPreferredSize(new java.awt.Dimension(130, 21));
		}
		{
			lServicio = new JLabel();
			super.jPanel1.add(lServicio);
			lServicio.setText("Cliente");
			lServicio.setHorizontalAlignment(SwingConstants.CENTER);
			lServicio.setPreferredSize(new java.awt.Dimension(100,21));
			lServicio.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			lServicio.setSize(100, 21);
			lServicio.setForeground(new Color(0,0,0));
		}
		{
			List ls = AccesoADatos.getInstance().getClientes();
			ls.add(0, new String("Todos"));
			ComboBoxModel cbServicioModel = 
				new DefaultComboBoxModel(
						ls.toArray());
			cbCliente = new JComboBox();
			cbCliente.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			super.jPanel1.add(cbCliente);
			cbCliente.setModel(cbServicioModel);
			cbCliente.setPreferredSize(new java.awt.Dimension(130, 21));
		}
		{
			lFechaFin = new JLabel();
			super.jPanel1.add(lFechaFin);
			lFechaFin.setText("Fecha fin");
			lFechaFin.setHorizontalAlignment(SwingConstants.CENTER);
			lFechaFin.setPreferredSize(new java.awt.Dimension(100,21));
			lFechaFin.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			lFechaFin.setSize(100, 21);
			lFechaFin.setForeground(new Color(0,0,0));
		}
		{
			cFechaFin = new JDateChooser();
			cFechaFin.setDate(new Date());
			cFechaFin.setBorder(BorderFactory.createLineBorder(new Color(0,0,0)));
			super.jPanel1.add(cFechaFin);
			cFechaFin.setPreferredSize(new java.awt.Dimension(130, 21));
		}
		this.pack();
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}


	@SuppressWarnings("unchecked")
	@Override
	public Vector cargarVector(Object object) {
		Vector v=new Vector();
		v.add(this.FormatearFecha((((Reserva)object).getTurno().getFecha())));
		v.add(((Reserva)object).getProfesional().toString());
		v.add(((Reserva)object).getCliente().toString());
		return v;
	}


	@SuppressWarnings("unchecked")
	@Override
	public List getLista() {
		Date inicio = this.cFechaInicio.getDate();
		Date fin = this.cFechaFin.getDate();
		List l = AccesoADatos.getInstance().getTurnosRangoFecha(inicio, fin);
		List result = new ArrayList<Reserva>();
		Criterio c = getCriterio();
		for (int i=0; i<l.size();i++){
			Reserva r=(Reserva)l.get(i);
			if (c.eval(r))
				result.add(r);
		}
		return result;
		
	}


	private Criterio getCriterio() {
		String profesional=this.cbProfesional.getSelectedItem().toString();
		String cliente=this.cbCliente.getSelectedItem().toString();
		Criterio c1=new CriterioClienteReservas(cliente);
		Criterio c2=new CriterioProfesionalReservas(profesional);
		Criterio c3=new CriterioCompuesto(c1, c2);
		return c3;
	}




}
